package com.jeesite.modules.codingrule.enums;

import com.jeesite.modules.common.vo.CommonSelectDataVO;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author rj
 */

@Getter
public enum BarcodeTypeEnum {
    ITEM_BARCODE("0", "物料条码"), INITIAL_BARCODE("1", "期初条码"), BARCODE_BATCH("2", "条码批次");

    private final String code;
    private final String name;

    BarcodeTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static List<CommonSelectDataVO> toCommonSelectDataVOList() {
        List<CommonSelectDataVO> list = new ArrayList<>();
        for (BarcodeTypeEnum type : values()) {
            CommonSelectDataVO vo =
                CommonSelectDataVO.builder().code(String.valueOf(type.getCode())).name(type.getName()).build();
            list.add(vo);
        }
        return list;
    }

    public static String getName(String code) {
        if(code == null){
            return "未知";
        }
        for (BarcodeTypeEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status.name;
            }
        }
        return null;
    }

}
